home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / comm / wnos5src.zip / IPDUMP.C < prev    next >
Text File  |  1993-10-14  |  2KB  |  91 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "config.h"
  4. #include "mbuf.h"
  5. #include "internet.h"
  6. #include "ip.h"
  7. #include "trace.h"
  8. #include "netuser.h"
  9.  
  10. void
  11. ip_dump(FILE *fp,struct mbuf **bpp,int check)
  12. {
  13.     struct ip ip;
  14.     int16 ip_len, length, csum = 0;
  15.  
  16.     if(bpp == NULLBUFP || *bpp == NULLBUF) {
  17.         return;
  18.     }
  19.     /* Sneak peek at IP header and find length */
  20.     if(((ip_len = ((*bpp)->data[0] & 0xf) << 2)) < IPLEN) {
  21.         trprintf(fp,"IP: bad header\n");
  22.         return;
  23.     }
  24.     if(check) {
  25.         csum = cksum(NULLHEADER,*bpp,ip_len);
  26.     }
  27.     ntohip(&ip,bpp);    /* Can't fail, we've already checked ihl */
  28.  
  29.     /* Trim data segment if necessary. */
  30.     length = ip.length - ip_len;            /* Length of data portion */
  31.     trim_mbuf(bpp,length);
  32.  
  33.     trprintf(fp,"IP: len %u %s->",ip.length,inet_ntoa(ip.source));
  34.     trprintf(fp,"%s ihl %u ttl %u",inet_ntoa(ip.dest),ip_len,uchar(ip.ttl));
  35.  
  36.     if(ip.tos != 0) {
  37.         trprintf(fp," tos %u",uchar(ip.tos));
  38.     }
  39.     if(ip.offset != 0 || ip.flags.mf) {
  40.         trprintf(fp," id %u offs %u",ip.id,ip.offset);
  41.     }
  42.     if(ip.flags.df) {
  43.         trprintf(fp," DF");
  44.     }
  45.     if(ip.flags.mf) {
  46.         trprintf(fp," MF");
  47.         check = 0;    /* Bypass host-level checksum verify */
  48.     }
  49.     if(ip.flags.congest) {
  50.         trprintf(fp," CE");
  51.     }
  52.     if(csum) {
  53.         trprintf(fp," CHECKSUM ERROR (%u)",csum);
  54.     }
  55.     if(ip.offset != 0) {
  56.         trprintf(fp,"\n");
  57.     } else {
  58.         trprintf(fp," prot ");
  59.         switch(uchar(ip.protocol)){
  60.         case IP_PTCL:
  61.             trprintf(fp,"IP\n");
  62.             ip_dump(fp,bpp,check);
  63.             break;
  64.         case TCP_PTCL:
  65.             trprintf(fp,"TCP\n");
  66.             tcp_dump(fp,bpp,ip.source,ip.dest,check);
  67.             break;
  68. #ifdef AX25
  69.         case AX25_PTCL:
  70.             trprintf(fp,"AX25\n");
  71.             ax25_dump(fp,bpp,check);
  72.             break;
  73. #endif
  74. #ifdef UDP
  75.         case UDP_PTCL:
  76.             trprintf(fp,"UDP\n");
  77.             udp_dump(fp,bpp,ip.source,ip.dest,check);
  78.             break;
  79. #endif
  80.         case ICMP_PTCL:
  81.             trprintf(fp,"ICMP\n");
  82.             icmp_dump(fp,bpp,ip.source,ip.dest,check);
  83.             break;
  84.         default:
  85.             trprintf(fp,"%u\n",uchar(ip.protocol));
  86.             break;
  87.         }
  88.     }
  89.     return;
  90. }
  91.